/*
 * jlb
 */
package com.jlb.user.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baidu.fsg.uid.UidGenerator;
import com.jlb.active.dao.ActiveRecordDAO;
import com.jlb.active.entity.ActiveRecord;
import com.jlb.core.base.BaseDAO;
import com.jlb.core.base.BaseSVImpl;
import com.jlb.core.entity.Page;
import com.jlb.core.enums.YNEnum;
import com.jlb.core.exceptions.*;
import com.jlb.core.tools.security.Md5;
import com.jlb.count.entity.Count;
import com.jlb.count.service.CountSV;
import com.jlb.jlb.dao.JlbOreLogDAO;
import com.jlb.jlb.entity.JlbOreLog;
import com.jlb.jlb.entity.JlbOreLogEvent;
import com.jlb.jlb.entity.JlbOreLogType;
import com.jlb.jlb.entity.TransferType;
import com.jlb.miner.dao.MinerItemDAO;
import com.jlb.miner.entity.MinerItem;
import com.jlb.miner.entity.PayType;
import com.jlb.platform.entity.PlatformAccount;
import com.jlb.setting.dao.SettingDAO;
import com.jlb.setting.entity.Setting;
import com.jlb.star.dao.StarLevelDAO;
import com.jlb.star.entity.StarLevel;
import com.jlb.user.dao.*;
import com.jlb.user.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userOreSV")
@Slf4j
public class UserOreSVImpl extends BaseSVImpl<UserOre, Long> implements UserOreSV {

    @Autowired
    private CountSV countSV;


    @Autowired
    private JlbOreLogDAO jlbOreLogDAO;

    @Autowired
    private UserActiveDAO userActiveDAO;
    @Autowired
    private ActiveRecordDAO activeRecordDAO;

    @Autowired
    private SettingDAO settingDAO;

    @Autowired
    private UserMinerDAO userMinerDAO;

    @Autowired
    private MinerItemDAO minerItemDAO;

    @Autowired
    private UserOreDAO userOreDAO;

    @Autowired
    private UserDAO userDAO;

    @Autowired
    private UserSV userSV;

    @Autowired
    private UserJlbDAO userJlbDAO;

    @Autowired
    private StarLevelDAO starLevelDAO;

    @Resource
    private UidGenerator uidGenerator;

    @Override
    protected BaseDAO getBaseDAO() {
        return userOreDAO;
    }

    /**
     * 保存account对象
     *
     * @param entity 实体
     * @throws BaseException
     */
    @Override
    public void save(UserOre entity) throws BaseException {
        super.save(entity);
    }

    /**
     * 加载一个对象UserOre
     *
     * @param id * @param userCode 用户编码
     * @return UserOre
     */
    @Override
    public UserOre load(java.lang.Long id, java.lang.String userCode) {
        if (id == null && userCode == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }

        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("userCode", userCode);
        return userOreDAO.load(param);
    }

    /**
     * 加载一个对象UserOre 通过id
     *
     * @param id
     * @return UserOre
     */
    @Override
    public UserOre loadById(java.lang.Long id) {
        if (id == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return userOreDAO.loadById(id);
    }

    /**
     * 加载一个对象UserOre 通过userCode
     *
     * @param userCode 用户编码
     * @return UserOre
     */
    @Override
    public UserOre loadByUserCode(java.lang.String userCode) {
        if (userCode == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return userOreDAO.loadByUserCode(userCode);
    }


    /**
     * 根据主键id,oldStates 共同更新 UserOre 的状态到newState状态
     *
     * @param id
     * @param newState  新状态
     * @param oldStates 旧状态集合
     */
    @Override
    public void updateStateById(java.lang.Long id, UserOreState newState, UserOreState... oldStates) {
        if (id == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        if (newState == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        if (oldStates == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        userOreDAO.updateStateById(id, new Date(), newState, oldStates);
    }

    /**
     * 根据主键id 更新 UserOre 的状态到另一个状态
     *
     * @param id
     * @param state 状态
     */
    @Override
    public void updateById(java.lang.Long id, UserOreState state) {
        if (id == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        userOreDAO.updateById(id, state, new Date());
    }

    /**
     * 根据主键userCode 更新 UserOre 的状态到另一个状态
     *
     * @param userCode 用户编码
     * @param state    状态
     */
    @Override
    public void updateByUserCode(java.lang.String userCode, UserOreState state) {
        if (userCode == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        userOreDAO.updateByUserCode(userCode, state, new Date());
    }


    /**
     * 删除对象UserOre
     *
     * @param id * @param userCode 用户编码
     * @return UserOre
     */
    @Override
    public void delete(java.lang.Long id, java.lang.String userCode) {
        if (id == null && userCode == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("userCode", userCode);
        userOreDAO.delete(param);
    }


    /**
     * 查询UserOre分页
     *
     * @param userOre 对象
     * @param offset  查询开始行
     * @param limit   查询行数
     * @return List<UserOre>
     */
    @Override
    public List<UserOre> list(UserOre userOre, int offset, int limit) {
        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }

        Map<String, Object> map = null;
        if (userOre != null) {
            map = JSON.parseObject(JSON.toJSONString(userOre, SerializerFeature.WriteDateUseDateFormat));
        } else {
            map = new HashMap<>();
        }
        return userOreDAO.list(map, new RowBounds(offset, limit));
    }

    @Override
    public int count(UserOre userOre) {
        Map<String, Object> map = null;
        if (userOre != null) {
            map = JSON.parseObject(JSON.toJSONString(userOre, SerializerFeature.WriteDateUseDateFormat));
        } else {
            map = new HashMap<>();
        }
        return userOreDAO.count(map);
    }

    /**
     * 查询UserOre分页
     *
     * @param id     * @param userCode  用户编码
     * @param offset 查询开始行
     * @param limit  查询行数
     * @return List<UserOre>
     */
    @Override
    public List<UserOre> list(java.lang.Long id, java.lang.String userCode, int offset, int limit) {
        if (offset < 0) {
            offset = 0;
        }

        if (limit < 0) {
            limit = Page.limit;
        }
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("userCode", userCode);
        return userOreDAO.list(param, new RowBounds(offset, limit));
    }

    @Override
    public int count(java.lang.Long id, java.lang.String userCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("userCode", userCode);
        return userOreDAO.count(param);
    }


    /**
     * 用户动态复投
     * 1.查询用户的矿机及矿机价格
     * 2.交易密码是否正确
     * 3.查询用户的激活码是否存在
     * 4.查询用户的金兰宝，矿石是否够用
     * 5.扣除用户的金兰宝，矿石
     * 6.为用户激活动态收益
     * 7.记录日志
     *
     * @param userCode    账户
     * @param payType     支付类型
     * @param pinPassword 交易密码
     */
    @Override
    public void recast(String userCode, String payType, String pinPassword) {
        if (StringUtils.isBlank(userCode) || StringUtils.isBlank(payType)) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        Map<String, Object> param = new HashMap<>();
        param.put("code", userCode);
        User user = userDAO.load(param);
        if (user == null) {
            throw new UserException(BaseException.BaseExceptionEnum.Result_Not_Exist);
        }

        // 1.查询用户的矿石账户
        UserOre userOre = userOreDAO.loadByUserCode(user.getCode());
        if (userOre == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Working);
        }
        if (UserOreState.getEnum(userOre.getState()) == UserOreState.Active) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Working);
        }

        UserMiner userMiner = userMinerDAO.loadByUserCode(user.getCode());
        if (userMiner == null) {
            throw new MinerItemException(BaseException.BaseExceptionEnum.Miner_Not_Exist);
        }
        MinerItem minerItem = minerItemDAO.loadByCode(userMiner.getMinerCode());
        if (minerItem == null) {
            throw new MinerItemException(BaseException.BaseExceptionEnum.Miner_Not_Exist);
        }
        //2.交易密码是否正确
        if (!Md5.md5(pinPassword).equals(user.getPinPassword())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Pin_Password_Is_Error);
        }

        // 3.查询用户的激活码是否存在,查询激活码数量
        YNEnum active_Coin_On_Off_OreYN = YNEnum.getYN(settingDAO.loadByK(Setting.Key.Active_Coin_On_Off_Ore.name()).getV());
        int active_Coin_Ore_Num = Integer.valueOf(settingDAO.loadByK(Setting.Key.Active_Coin_Ore_Num.name()).getV());


        // 4.查询用户的金兰宝，矿石是否够用
        PayType payTypeEnum = PayType.getEnum(payType);
        Map<String, Object> params = new HashedMap();
        params.put("userCode", user.getCode());
        UserJlb userJlb = userJlbDAO.load(params);
        if (userJlb == null) {
            throw new UserJlbException(BaseException.BaseExceptionEnum.Jlb_Not_Exist);
        }
        if (UserJlbState.Frozen == UserJlbState.getEnum(userJlb.getState())) {
            throw new UserJlbException(BaseException.BaseExceptionEnum.Jlb_Frozen_Error);
        }

        if (payTypeEnum == PayType.Jlb_Ore) {
            if (minerItem.getMixJlb() > userJlb.getJlb()) {
                throw new UserJlbException(BaseException.BaseExceptionEnum.Jlb_Not_Enough_Error);
            }

            if (userOre == null) {
                throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Exist);
            }
            if (minerItem.getMixOre() > userOre.getOre()) {
                throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
            }

        } else {
            if (minerItem.getJlb() > userJlb.getJlb()) {
                throw new UserJlbException(BaseException.BaseExceptionEnum.Jlb_Not_Enough_Error);
            }
        }

        //扣除激活币
        if (active_Coin_On_Off_OreYN == YNEnum.Y) {
            param.clear();
            param.put("userCode", user.getCode());
            UserActive userActive = userActiveDAO.load(params);
            if (userActive == null) {
                userActiveDAO.insert(new UserActive(userCode, 0));
                throw new UserActiveException(BaseException.BaseExceptionEnum.Active_Not_Enough_Error);
            }
            if (userActive.getActive() > active_Coin_Ore_Num) {
                userActive.setActive(userActive.getActive() - active_Coin_Ore_Num);
                userActiveDAO.update(userActive);
                activeRecordDAO.insert(new ActiveRecord(String.valueOf(active_Coin_Ore_Num * (-1)), user.getCode(), "用户动态复投扣除激活币[" + active_Coin_Ore_Num + "]"));
            } else {
                throw new UserActiveException(BaseException.BaseExceptionEnum.Active_Not_Enough_Error);
            }
        }


        // 5.扣除用户的金兰宝，矿石
        UserJlb platformJlb = userJlbDAO.loadByCode(PlatformAccount.PlatformAccountEnum.Platform.name());

        //金兰宝+矿石支付
        if (payTypeEnum == PayType.Jlb_Ore) {
            userJlb.setJlb(userJlb.getJlb() - minerItem.getMixJlb());
            userJlbDAO.update(userJlb);

            //平台账户接收
            platformJlb.setJlb(platformJlb.getJlb() + minerItem.getMixJlb());
            userJlbDAO.update(platformJlb);
            //统计
            countSV.saveOrUpdate(new Count(null, String.valueOf(minerItem.getMixJlb()), null, null));
            //记录日志变化
            jlbOreLogDAO.insert(new JlbOreLog(userJlb.getCode(), PlatformAccount.PlatformAccountEnum.Platform.name(),
                    minerItem.getMixJlb(), JlbOreLogType.JLB.name(), JlbOreLogEvent.Re_Cast.name(), userJlb.getJlb() + minerItem.getMixJlb(),
                    userJlb.getJlb(), platformJlb.getJlb() - minerItem.getMixJlb(), platformJlb.getJlb()));


            userOre.setOre(userOre.getOre() - minerItem.getMixOre());
            userOreDAO.update(userOre);

            //平台账户接收
            UserOre platformOre = userOreDAO.loadByUserCode(PlatformAccount.PlatformAccountEnum.Platform.name());
            platformOre.setOre(platformOre.getOre() + minerItem.getMixOre());
            userOreDAO.update(platformOre);


            //统计
            countSV.saveOrUpdate(new Count(null, null, null, String.valueOf(minerItem.getMixOre())));
            //记录日志变化
            jlbOreLogDAO.insert(new JlbOreLog(userJlb.getCode(), PlatformAccount.PlatformAccountEnum.Platform.name(),
                    minerItem.getMixOre(), JlbOreLogType.ORE.name(), JlbOreLogEvent.Re_Cast.name(), userOre.getOre() + minerItem.getMixOre(),
                    userOre.getOre(), platformOre.getOre() - minerItem.getMixOre(), platformOre.getOre()));
        } else {

            //纯金兰宝支付
            userJlb.setJlb(userJlb.getJlb() - minerItem.getJlb());
            userJlbDAO.update(userJlb);

            //平台账户接收
            platformJlb.setJlb(platformJlb.getJlb() + minerItem.getJlb());
            userJlbDAO.update(platformJlb);
            //统计
            countSV.saveOrUpdate(new Count(null, String.valueOf(minerItem.getJlb()), null, null));
            //记录日志变化
            jlbOreLogDAO.insert(new JlbOreLog(userJlb.getCode(), PlatformAccount.PlatformAccountEnum.Platform.name(),
                    minerItem.getMixJlb(), JlbOreLogType.JLB.name(), JlbOreLogEvent.Re_Cast.name(), userJlb.getJlb() + minerItem.getJlb(),
                    userJlb.getJlb(), platformJlb.getJlb() - minerItem.getJlb(), platformJlb.getJlb()));
        }

        // 6.为用户激活动态收益
        userOre.setState(UserOreState.Active.name());
        userOre.setLayerTotalOre(0);
        userOreDAO.update(userOre);

    }

    /**
     * 用户相互转矿石
     * 1.数据合法性验证：非空，是否存在，金额是否足够
     * 2.判断用户密码
     * 3.用户之间是否可以转账
     * 4.发送者减少相应的矿石
     * 5.接收者增加相应的矿石
     * 6.添加记录日志
     *
     * @param sendUser      转赠用户编码
     * @param acceptAccount 接受账户
     * @param num           数量
     * @param pinPassword   支付密码
     */
    @Override
    public void transfer(User sendUser, String acceptAccount, Integer num, String pinPassword) {
        //1.数据合法性验证：非空，是否存在，金额是否足够
        if (StringUtils.isEmpty(acceptAccount) || num == null || StringUtils.isEmpty(pinPassword)) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        //转账者是否激活状态
        if (UserState.Active != UserState.getEnum(sendUser.getState())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.User_Not_Active);
        }
        //接收者是否存在
        User acceptUser = userDAO.loadByAccount(acceptAccount);
        if (acceptUser == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.User_Error);
        }
        if (UserState.Active != UserState.getEnum(acceptUser.getState())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.User_Not_Active);
        }
        //判断是否给自己转账
        if (sendUser.getCode().equals(acceptUser.getCode())) {
            throw new UserJlbException(BaseException.BaseExceptionEnum.Not_Allow_Transfer_Yourself);
        }
        //判断矿石金额是否足够
        if (sendUser.getUserOre() == null || sendUser.getUserOre().getOre() < num) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
        }
        //2.交易密码是否正确
        if (!Md5.md5(pinPassword).equals(sendUser.getPinPassword())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Pin_Password_Is_Error);
        }
        //3.用户之间是否可以转账
        boolean result = userSV.isAllowTranfer(sendUser.getCode(), acceptUser.getCode());
        if (!result) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Not_Allow_Transfer);
        }
        //4.发送者减少相应的矿石
        UserOre sendUserOre = userOreDAO.loadByUserCode(sendUser.getCode());
        if (sendUserOre == null) {
            userOreDAO.insert(new UserOre().init(sendUser.getCode()));
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
        }
        if (sendUserOre.getOre() < num) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
        }
        sendUserOre.setOre(sendUserOre.getOre() - num);
        userOreDAO.update(sendUserOre);

        //5.接收者增加相应的矿石
        UserOre acceptUserOre = this.watchUserOre(acceptUser.getCode());
        acceptUserOre.setOre(acceptUserOre.getOre() + num);
        userOreDAO.update(acceptUserOre);


        //6. 记录日志
        jlbOreLogDAO.insert(new JlbOreLog(sendUser.getCode(), acceptUser.getCode(), num, JlbOreLogType.ORE.name(), JlbOreLogEvent.Transfer.name(),
                sendUserOre.getOre() + num, sendUserOre.getOre(), acceptUserOre.getOre() - num, acceptUserOre.getOre()));
    }


    /**
     * 查看用户是否有矿石账户，如果没有，创建一个账户
     *
     * @param userCode 用户编码
     * @return
     */
    @Override
    public UserOre watchUserOre(String userCode) {
        UserOre userOre = userOreDAO.loadByUserCode(userCode);
        if (userOre == null) {
            userOre = new UserOre();
            userOre.setUserCode(userCode);
            userOre.setOre(0);
            userOre.setLayerTotalOre(0);
            userOre.setRefineTotalOre(0);
            userOre.setState(UserOreState.Active.name());
            userOreDAO.insert(userOre);
        }
        return userOre;
    }

    /**
     * 计算未领取矿石
     *
     * @param userCode 用户编码
     * @return
     */
    @Override
    public int calculateUnclaimedOre(String userCode) {
        User user = userDAO.loadByCode(userCode);
        if (user == null) {
            return 0;
        }

        Map<String, Object> params = new HashedMap();
        long star = user.getStar();
        params.put("starLevel", String.valueOf(star));
        StarLevel starLevel = starLevelDAO.load(params);
        if (starLevel == null) {
            return 0;
        }

        if (StringUtils.isBlank(starLevel.getMultiple())) {
            return 0;
        }

        UserOre userOre = userOreDAO.loadByUserCode(userCode);
        if (userOre == null) {
            return 0;
        }


        UserMiner userMiner = userMinerDAO.loadByUserCode(userCode);
        if (userMiner == null) {
            return 0;
        }
        MinerItem minerItem = minerItemDAO.loadByCode(userMiner.getMinerCode());
        if (minerItem == null) {
            return 0;
        }
        Integer price = Integer.parseInt(minerItem.getPrice());
        Integer oreIncomeUpperLimit = price * Integer.parseInt(starLevel.getMultiple());
        return oreIncomeUpperLimit - userOre.getLayerTotalOre() < 0 ? 0 : oreIncomeUpperLimit - userOre.getLayerTotalOre();
    }

    /**
     * 提炼矿石
     * 1.判断数据合法性
     * 用户状态是否正常
     * 2.用户余额是否足够
     * 3.查询用户星级，根据星级查询提炼比例
     * 4.修改用户可提炼数量和用户矿石总数量
     *
     * @param userCode    转赠用户编码
     * @param num         数量
     * @param pinPassword 支付密码
     */
    @Override
    public void refineOre(String userCode, Integer num, String pinPassword) {
        if (StringUtils.isEmpty(userCode) || num == null || StringUtils.isEmpty(pinPassword)) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        //转账者是否存在
        User user = userDAO.loadByCode(userCode);
        if (user == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.User_Error);
        }
        if (UserState.Active != UserState.getEnum(user.getState())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.User_Not_Active);
        }
        //2.判断交易密码是否正确
        if (!Md5.md5(pinPassword).equals(user.getPinPassword())) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Pin_Password_Is_Error);
        }
        //判断矿石金额是否足够
        if (user.getUserOre() == null || user.getUserOre().getRefineTotalOre() < num) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
        }
        //查询用户星级规则
        Long star = user.getStar();
        Map<String, Object> params = new HashedMap();
        params.put("starLevel", String.valueOf(star));
        StarLevel starLevel = starLevelDAO.load(params);
        if (starLevel == null) {
            throw new UserOreException(BaseException.BaseExceptionEnum.Star_Is_Error);
        }
        String refiningRate = starLevel.getOreRefiningRate();
        Integer rate = Integer.valueOf(refiningRate);
        BigDecimal rateDecimal = new BigDecimal(rate).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_FLOOR);
        int refiningNum = rateDecimal.multiply(new BigDecimal(num)).intValue();
        //修改用户可提炼数量和用户矿石总数量
        UserOre userOre = user.getUserOre();
        userOre.setRefineTotalOre(userOre.getRefineTotalOre() - num);
        userOre.setOre(userOre.getOre() + refiningNum);
        userOreDAO.update(userOre);
    }

    @Override
    public Integer countOre() {
        return userOreDAO.countOre();
    }

    @Override
    public Integer countRefineOre() {
        return userOreDAO.countRefineOre();
    }

    @Override
    public void platUpdateOre(String account, Integer num, TransferType transferType) {
        if (StringUtils.isEmpty(account) || num == null) {
            throw new UserJlbException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }

        User user = userDAO.loadByAccount(account);
        if (user == null) {
            throw new UserJlbException(BaseException.BaseExceptionEnum.Result_Not_Exist);
        }
        String userCode = user.getCode();
        UserOre userOre = this.watchUserOre(userCode);
        if (transferType == TransferType.Out) {
            int ore = userOre.getOre();
            if (ore == 0 || ore < num) {
                throw new UserJlbException(BaseException.BaseExceptionEnum.Ore_Not_Enough_Error);
            }
        }
        //是否为用户充值为用户充值
        if (transferType == TransferType.In) {
            num = num * (-1);
        }
        userOre.setOre(userOre.getOre() - num);
        userOreDAO.update(userOre);

        //添加记录
        if (transferType == TransferType.In) {
            jlbOreLogDAO.insert(new JlbOreLog(PlatformAccount.PlatformAccountEnum.Platform.name(), userCode,
                    num * (-1), JlbOreLogType.ORE.name(), JlbOreLogEvent.Recharge.name(), userOre.getOre() + num,
                    userOre.getOre(), 0, 0));
        } else {
            jlbOreLogDAO.insert(new JlbOreLog(userCode, PlatformAccount.PlatformAccountEnum.Platform.name(),
                    num, JlbOreLogType.ORE.name(), JlbOreLogEvent.Deduct.name(), userOre.getOre() + num,
                    userOre.getOre(), 0, 0));
        }
    }

}
